package com.glw.sso.platform.web.generator;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.glw.sso.platform.common.base.BaseController;
import com.glw.sso.platform.common.base.BaseEntity;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class CodeGenerator {

    private static final String[] baseField = {"create_user", "create_user_id", "update_user", "update_user_id",
            "create_time", "update_time", "version", "is_delete"};

    public static void main(String[] args) {
        // doc:https://mp.baomidou.com/guide/generator-new.html#%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8
        FastAutoGenerator.create(
                        "jdbc:mysql://4uy4759174.zicp.vip:33757/mydatabase?characterEncoding=UTF-8",
                        "root", "qazwsx")
                .globalConfig(builder -> {
                    builder.author("AutoGenerator") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://CodeGenerator"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.glw.sso.platform") // 设置父包名
                            .moduleName("domain") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://CodeGenerator")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.likeTable(new LikeTable("system"))
                            // .addInclude("system_user","") // 设置需要生成的表名
                            .addTablePrefix("t_", "system_") // 设置过滤表前缀
                            .entityBuilder().enableLombok() // 启用Lombok
                            .superClass(BaseEntity.class) // 设置父类
                            //.addSuperEntityColumns(baseField) // 设置父类公共字段
                            .addIgnoreColumns(baseField)
                            .serviceBuilder().formatServiceFileName("%sService")
                            .mapperBuilder().enableMapperAnnotation()
                            .controllerBuilder().superClass(BaseController.class);
                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
